package com.xuerhua.yxt.view;

import java.util.Map;

import org.apache.commons.lang.StringUtils;

import com.xuerhua.yxt.common.Const;
import com.xuerhua.yxt.common.enums.ResourceType;
import com.xuerhua.yxt.model.OrganizeDepart;
import com.xuerhua.yxt.model.SysResource;
import com.xuerhua.yxt.utils.StringUtil;
import com.xuerhua.yxt.wechat.utils.WechatGlobalMap;

public class SysResourceView extends SysResource {
	
	private static final long serialVersionUID = 2985481212087041631L;

	public String getResourceTypeValue() {
		return ResourceType.getValue(super.getResourceType());
	}
	
	public String getResourceUrlValue() {
		String resourceUrl = super.getResourceUrl();
		if(!StringUtil.isNotNullOrZero(super.getIsExtLink()) ){
			if(StringUtils.isNotBlank(resourceUrl) && resourceUrl.indexOf("?") == -1) {
				return resourceUrl + "?from=sys";
			}
			return resourceUrl + "&from=sys";
		}
		return resourceUrl;
	}
	
	@SuppressWarnings("unchecked")
	public String getIdsValue() {
		if(StringUtils.isBlank(super.getIds()) || super.getIds().equals("0")) {
			return "";
		}
		Map<String, OrganizeDepart> map = (Map<String, OrganizeDepart>) WechatGlobalMap.get(Const.CACHE_ORGANIZE_DEPART).getValue();
		String[] strings = super.getIds().split(",");
		String value = "";
		for(int i = 0; i < strings.length; i++) {
			OrganizeDepart currO = map.get(strings[i]);
			if(currO == null) {
				continue;
			}
			value += map.get(strings[i]).getPosition();
			if((i+1) != strings.length) value += ",";
		}
		return value;
	}

}
